home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
win_u_z
/
wt_jan92.zip
/
DPMI.ZIP
/
WINDPMI.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-12-23
|
4KB
|
147 lines
{*********************************************************}
{* WINDPMI.PAS 1.00 *}
{* Copyright (c) TurboPower Software 1991. *}
{* All rights reserved. *}
{*********************************************************}
{$S-,R-}
unit WinDPMI;
{-Windows 3.x/TPW interface to DPMI services}
interface
uses
WinTypes,
WinProcs;
type
SegOfs = {structure of a pointer}
record
Ofst, Segm : Word;
end;
DoubleWord
= record
LoWord : Word;
HiWord : Word;
end;
DPMIRegisters =
record
drDI : LongInt;
drSI : LongInt;
drBP : LongInt;
drReserved : LongInt;
drBX : LongInt;
drDX : LongInt;
drCX : LongInt;
drAX : LongInt;
drFlags : Word;
drES : Word;
drDS : Word;
drFS : Word;
drGS : Word;
drIP : Word;
drCS : Word;
drSP : Word;
drSS : Word;
end;
function InRealMode : Boolean;
{-Returns true if Windows is operating in real mode.}
function SimulateRealModeInt(IntNo : Byte; StackWords : Word;
var Regs : DPMIRegisters) : Word;
{-Simulates a real mode interrupt. Copies the values from the record Regs
into the physical registers. StackWords specifies the number of bytes to
copy from the protected mode to the real mode stack. Returns 0 for success
or DPMI error code.}
procedure AllocateRealModeCallbackAddr(CallbackProc : Pointer;
var Regs : DPMIRegisters;
var Callback : Pointer);
{-Allocates a real mode callback. Ensure that Regs refers to a variable that
will remain static until FreeRealModeCallBack is called. Returns the real
mode callback address in CallBack. CallbackProc specifies a protected mode
procedure to be called from the real mode callback. See DPMI
specifications for more info on the protected mode procedure. Returns Nil
in CallBack if unable to allocate a real mode callback.}
function FreeRealModeCallbackAddr(P : Pointer) : Word;
{-Frees a real mode callback previously allocated with
AllocateRealModeCallbackAddr.}
procedure GetRealModeIntVector(IntNo : Byte; var Vector : Pointer);
{-Returns the value of an interrupt vector (like GetIntVec).}
function GetCPUFlags : Byte;
{-A little routine to return the current state of the CPU flags.}
implementation
function SimulateRealModeInt(IntNo : Byte; StackWords : Word;
var Regs : DPMIRegisters) : Word; Assembler;
asm
xor bx,bx
mov bl,IntNo
mov cx,StackWords
les di,Regs
mov ax,0300h
int 31h
jc @@ExitPoint
xor ax,ax
@@ExitPoint:
end;
function GetCPUFlags : Byte; Assembler;
asm
lahf
mov al,ah
end;
function InRealMode : Boolean;
begin
InRealMode := GetWinFlags and wf_PMode = 0;
end;
procedure AllocateRealModeCallbackAddr(CallbackProc : Pointer;
var Regs : DPMIRegisters;
var Callback : Pointer); Assembler;
asm
push ds
lds si,CallbackProc
les di,Regs
mov ax,0303h
int 31h
jnc @@Exitpoint
xor cx,cx
xor dx,dx
@@ExitPoint:
les di,Callback
mov word ptr es:[di],dx
mov word ptr es:[di+2],cx
pop ds
end;
function FreeRealModeCallbackAddr(P : Pointer) : Word; Assembler;
asm
mov cx,word ptr P+2
mov dx,word ptr P
mov ax,0304h
int 31h
jc @@ExitPoint
xor ax,ax
@@ExitPoint:
end;
procedure GetRealModeIntVector(IntNo : Byte; var Vector : Pointer); Assembler;
asm
mov ax,0200h
mov bl,IntNo
int 31h
les di,Vector
mov word ptr es:[di],dx
mov word ptr es:[di+2],cx
end;
end.